package com.mjk.common.util;


import com.mjk.common.tools.logger.BizLogger;

import javax.sql.rowset.serial.SerialClob;
import java.io.BufferedReader;
import java.io.Reader;
import java.sql.Clob;

public class ClobUtils {
	private ClobUtils(){}
	public static String clobToString(Clob clob)  {
		try{
			String ret;
			if(clob==null){
				return null;
			}
			Reader read = clob.getCharacterStream();
			BufferedReader br = new BufferedReader(read);
			String s = br.readLine();
			StringBuilder sb = new StringBuilder();
			while (s != null) {
				sb.append(s);
				s = br.readLine();
            }
			ret = sb.toString();
			br.close();
			read.close();
			return ret;
		}catch(Exception e){
			BizLogger.error(e);
		}
		return "";
	}

	public static Clob stringToClob(String str){
        if (ObjectUtils.isEmpty(str)) {
            return null;
        }
		try {
			return new SerialClob(str.toCharArray());
		} catch (Exception e) {
			BizLogger.error(e);
		} 
		return null;
	}
}
